package com.ptmall.app.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.WalletRechargeBean;
import com.ptmall.app.utils.TimeUtil;

import java.util.List;


/**
 * Created by MacBook on 17/7/15.
 */


public class WalletListAdapter extends BaseAdapter {
    private Context mContext;
    List<WalletRechargeBean> list;

    public WalletListAdapter(Context context, List<WalletRechargeBean> list){
        this.mContext = context;
        this.list = list;
    }

    public void pushData( List<WalletRechargeBean> list){
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(list == null){
            return 0;
        }
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView =
                    LayoutInflater.from(mContext).inflate(R.layout.item_recharge, parent, false);
            holder = new ViewHolder();
            holder.recharge_num = (TextView)convertView.findViewById(R.id.recharge_num);
            holder.recharge_text = (TextView)convertView.findViewById(R.id.recharge_text);
            holder.recharge_time = (TextView)convertView.findViewById(R.id.recharge_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.recharge_time.setText(TimeUtil.getStrTime(list.get(position).create_time+""));
        holder.recharge_text.setText(list.get(position).content);
        holder.recharge_num.setText(list.get(position).amount);
        return convertView;
    }

    private class ViewHolder {
        private TextView recharge_time,recharge_text,recharge_num;
    }
}
